<include file="__THEME__/_header" />
<style type="text/css">
  .login-info .error-box{top:440px;height: 32px;}
  .login-info .error-box p{line-height: 32px;}
</style>
<div id="page-wrap" class="clearfix"> 
  <!--***登录***-->
  <div class="login-main clearfix">
    <!-- <div class="login-banner"><img  src="{$login_bg}"/></div> -->
    <!--登录面板-->
    <div class="login-board" style="width:300px;height:300px;">
      <h3>学前儿童综合管理和资源共享平台</h3>
      <form id="ajax_login_form" autocomplete="false">
        <div class="login-info">
          <div class="input-outer"> <span class="ui-user"></span>
	<input type="text" name="login_email" class="text" placeholder='输入邮箱或用户名登录'/>
          </div>
          <div class="input-outer">
            <span class="ui-loginPwd"></span><label class="l-login login_password" style="color:#888;"></label>
	    <input type="password" name="login_password" class="text" style=" position:absolute; z-index:100;" placeholder="输入密码" value=""/>
          </div>
          <div id="js_login_input"></div>
          <div class="mb20"><a class="act-but submit" id="submit-btn" href="javascript:;">登录</a></div>
          <div class="clearfix mb20">
            <a class="login-rm" event-node="login_remember" href="javascript:;">
              <span class="check-ok">
              <input type="hidden" name="login_remember" value="0" id="check-box" class="checkbox"/>
              </span>记住用户名
            </a>
          </div>
      </form>
    </div>
  </div>
</div>
<eq name='site.site_online_count' value='1'>
  <!--<script src="{:SITE_URL}/online_check.php?uid={$mid}&uname={$user.uname}&mod={:MODULE_NAME}&app={:APP_NAME}&act={:ACTION_NAME}&action=trace"></script>-->
</eq>
<script src="__THEME__/js/login.js" type="text/javascript"></script>
<script src="https://cdn.bootcss.com/crypto-js/3.1.9-1/crypto-js.min.js"></script>
<script src="https://cdn.bootcss.com/crypto-js/3.1.9-1/aes.min.js"></script>

<script type="text/javascript">
$(function(){

    /**
     * 接口数据加密函数
     * @param str string 需加密的json字符串
     * @param key string 加密key(16位)
     * @param iv string 加密向量(16位)
     * @return string 加密密文字符串
     */
    function encrypt(str, key, iv) {
        //密钥16位
        var key = CryptoJS.enc.Utf8.parse(key);
        //加密向量16位
        var iv = CryptoJS.enc.Utf8.parse(iv);
        var encrypted = CryptoJS.AES.encrypt(str, key, {
            iv: iv,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.ZeroPadding
        });
        return encrypted;
    }

    // 提交发布前验证
    var checkLoginForm = function() {
        if(login_submiting)
            return;

        if($('#account_input').val().length == 0) {
            $('#account_input').focus();
            return false;
        }
        if($('#pwd_input').val().length == 0) {
            $('#pwd_input').focus();
            return false;
        }
        return true;
    };

    var login_submiting = false;

    function doSubmit() {
        login_submiting = true;

        //获取当前时间戳13位 + 3位字符
        var timestamp = new Date().getTime().toString() + "WZH";
        //加密密钥16位
        var encrypt_key = '1519699179001WZH';
        //加密向量16位
        var iv = 'ZZWBKJ_ZHIHUAWEI';
        //要加密的数据
        var encrypt_string = $('input[name="login_password"]').val();
        //加密后密文（加密函数在function.js文件中）
        var encrypted_string = encrypt(encrypt_string, encrypt_key, iv);

        var formData = new FormData()
        formData.append('login_email', $('input[name="login_email"]').val())
        formData.append('login_password', encrypted_string)
        formData.append('login_remember', $('input[name="login_remember"]').val())

        $.ajax({
            url:"{:U('public/Passport/doLogin')}",
            type: "post",
            data: formData,
            contentType: false,
            processData: false,
            dataType: 'json',
            beforeSend: checkLoginForm,
            success: function(i) {
                console.log(i)
                // var i = eval("("+e+")");
                login_submiting = false;
                if(i.status==1){
                    $('#js_login_input').html('<p>'+i.info+'</p>').show();
                    if(i.data==0){
                        window.location.href = "{:U('public/Index/index')}";
                    }else{
                        window.location.href = i.data;
                    }
                }else{
                    $('#js_login_input').html('<p>'+i.info+'</p>').show();
                    // window.setTimeout("window.location.reload()",3000);
                }
                setTimeout(function(){
                    $("#js_login_input").fadeOut(800);
                },3000);
            }
        })
    }

    //回车自动提交
    $('body').keypress(function(event){
        if(event.which==13){
            doSubmit();
        }
    });

    $('#submit-btn').on('click', function() {
        doSubmit();
    })


    var bg = "<?php if($login_bg) { echo $login_bg; } else { ?>__THEME__/image/login_bj.jpg<?php } ?>";
    $('body').css('background','url('+bg+')');
    $('body').css('background-repeat','no-repeat');
    $('body').css('background-position','center');
    $('body').css('background-attachment','fixed');
})
</script>
